home *** CD-ROM | disk | FTP | other *** search
- Path: news.nstn.ca!news
- From: keichele@ac.dal.ca (Klaus Eichele)
- Newsgroups: comp.lang.c
- Subject: Re: command line argument help
- Date: Sun, 28 Jan 1996 05:43:36 GMT
- Organization: Dalhousie University
- Message-ID: <4eekdi$9d@news.nstn.ca>
- References: <4edfth$ok@muss.CIS.McMaster.CA> <4ee3js$h57@umbc9.umbc.edu>
- NNTP-Posting-Host: rewasylishen.chem.dal.ca
- X-Newsreader: Forte Free Agent 1.0.82
-
- schlein@umbc.edu (Jonas J. Schlein) wrote:
-
- >In article <4edfth$ok@muss.CIS.McMaster.CA>, <shadowfax> wrote:
- >|> to all the c gods out there:
-
- >I don't see any, but I'll try to help anyway...
-
- >|> i am not having too much success with command line arguments. i am
- >|> trying to make a simple sumation executable for dos. i am using borland
- >|> c++ v3.1. what i want as the end result is the user just types:
- >|>
- >|> c:\> sum 6 3
- >|>
- >|> and the executable would output an answer of 9. the following is my program:
- >|>
- >|> #include <stdio.h>
- >|> #include <stdlib.h>
- >|>
- >|> int main(char *argv[])
-
- >Well there ya go! This is an illegal definition of main(). Instead use
- >int main (int argc, char *argv[]).
-
- >|> {
- >|> int iSum = 0;
- >|>
- >|> iSum = atoi(argv[1]) + atoi(argv[2]);
- >|> printf("\nthe answer is %d", iSum);
-
- >You may want to end the printf() with a '\n' as well.
-
- >|> return(0);
-
- >Good going...You get bonus points!
-
- >|> }
- >|>
- >|> when i compile and run, it always outputs an anser of 0. can anyone tell
- >|> me what's wrong?
-
- >Already did...Make the change to the definition of main() and you'll be good
- >to go!
- >--
- >"If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- >Jonas J. Schlein (schlein@gl.umbc.edu)
-
- Maybe one should add that in such instances it is highly advisable to
- check the value of argc itself before doing any processing (e.g., to
- display a message showing proper use/syntax of the program in case the
- wrong number of arguments has been supplied).
-
- Good Luck,
- Klaus
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Klaus Eichele keichele@ac.dal.ca
- http://ac.dal.ca/~keichele/keichele.html
-
-